import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
// axios
import axios from 'axios'
import Qs from 'qs'
import 'normalize.css'


// mavonEditor
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'

//QS是axios库中带的，不需要我们再npm安装一个
Vue.prototype.axios = axios;
Vue.prototype.qs = Qs;
Vue.config.productionTip = false
// use
Vue.use(mavonEditor)

// axios 配置
axios.defaults.baseURL = 'https://xiangtanmarujizhawangluokejiyouxiangongsi.xyz/gzh';
axios.defaults.headers.token = localStorage.getItem("token");
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

// 权限验证
router.beforeEach((to, from, next) => {
	
	let token = localStorage.getItem("token")
	//  有skip的可以跳过
	if (to.matched.some(record => record.meta.skip)) {
		console.log(to.matched[0].meta.skip)
		next()
	} else {
		//没有token需要登录
			if(token==null || token=='') {
				next("/user/login")
			}else{
				next()
			}
	}

})

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    return response;
  }, function (error) {
		// alert((error+' ').indexOf('10000'))
		if((error+'').indexOf('10000')>=0) {
			router.push("/user/login")
		}
    return Promise.reject(error);
});

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')